package com.monitor.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.monitor.entity.ErpCustomerCar;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客户车辆表 Mapper 接口
 * </p>
 *
 * @author LX
 * @since 2018-09-05
 */
public interface ErpCustomerCarMapper extends BaseMapper<ErpCustomerCar> {
	@Select("select * From erp_customer_car cc where cc.customer_id in (${cusids})")
	public List<ErpCustomerCar> selectByCusids(@Param("cusids")String cusids);

    @Select("SELECT car.*,insu.ins_property as insProperty,insu.insurancepolicyno,insu.insure_dt as insureDt ,insu.failure_dt as failureDt from erp_customer_car car LEFT JOIN erp_insurance insu ON car.car_plate =insu.car_number WHERE car.customer_id IN(${custIds})")
	List<Map<String,Object>> getCatInsurance(@Param("custIds")String custIds);

    @Select("SELECT car.*,insu.ins_property as insProperty,insu.insurancepolicyno,insu.insure_dt as insureDt ,insu.failure_dt as failureDt from erp_customer_car car LEFT JOIN erp_insurance insu ON car.car_plate =insu.car_number WHERE car.customer_id IN(${custIds})")
    List<Map<String,Object>> getCatInsuranceList(@Param("custIds")String custIds);
    
    @Select("SELECT * FROM erp_customer_car WHERE car_plate=#{plate}")
    public ErpCustomerCar selectByPlate(@Param("plate")String plate);
    
    @Select("SELECT cc.* from erp_customer_car cc where cc.id=(select cta.car_id from erp_car_tire_archives cta where cta.tire_id=#{tireId})")
    public ErpCustomerCar selectByTireId(@Param("tireId")int tireId);
    
    @Select("SELECT * FROM  erp_customer_car  c where  c.customer_id IN (SELECT  CC.id  from  erp_customer  CC WHERE CC.cus_code =#{code} ) ORDER by c.car_number ASC")
    public List<ErpCustomerCar> selectByCode(@Param("code")String code);
    
    //数据纠错 车辆换里程查询
    @Select("SELECT c.id,c.cus_name as cusName,c.cus_code as cusCode,cc.id as carId,cc.car_mileage as carMileage,cc.input_attn as inputAttn,cc.gh_time as ghTime,cc.car_plate as carPlate FROM erp_customer c, erp_customer_car cc WHERE c.id = cc.customer_id AND ( c.cus_code LIKE #{keyWord} OR c.cus_name LIKE #{keyWord} OR cc.car_plate LIKE #{keyWord} ) ")
    public List<Map<String, Object>> selectByKeyWord(@Param("keyWord")String keyWord);
    
    //根据id查询客户所有车牌号
    @Select("SELECT cc.car_plate FROM erp_customer_car as cc WHERE cc.customer_id=#{custId}")
    public List<String> selectPlateByCustId(@Param("custId")int custId);
}
